
/**
 * 服务机构 js
 */
var common = {};

common.paginationQuery = function(pn) {
	var name = $("#searchKeyWords").val();
	var params = {};
	params.companyName = name;
	params.auditStatus = $("#_auditStatus").val();
	params.page = pn;
	server.ajaxLoadTableList({
		url:server.url + "/manage/serviceManage/company/list",	// post请求url路径--必填
		params:params,
		paginationTable:'data-table',
		paginationFooter:'data-pagination',
		checkbox:true,
		columns:[{
			field:'companyName',	
			title:'公司名称',
			width:150,
			formatter:function(value,row){
				var result = '<a href="javascript:server.openModalBox(\'/manage/serviceManage/company/edit/' + row.id + '/1\',\'编辑\',800);">' + value + '</a>';
				return result;
			}
		},{
			field:'legalPerson',
			title:'法人',
			width:100
		},{
			field:'officeContactNumber',
			title:'联系方式',
			width:150
		},{
			field:'enterpriseType',
			title:'企业类型',
			width:80
		},{
			field:'auditStatus',
			title:'审核状态',
			width:80,
			formatter:function(value,row){
				var result = "--";
				if(value === "0"){
					result = "待审核";	
				}else if(value === "1"){
					result = "已通过";
				}else if(value === "2"){
					result = "未通过";
				}
				return result;
			}
		},{
			field:'updatedUser.userName',
			title:'更新人',
			width:100
		},{
			field:'updateTime',
			title:'更新时间',
			width:125,
			formatter:function(value,row){
				var updateTime = '--';
				if(value != null && value > 0){
					updateTime = new Date(value).format('yyyy-MM-dd hh:mm:ss');
				}
				return updateTime;
			}
		},{
			field:'action',	// 如果此为操作按钮时, field则应写成active, 此值固定!!!
			title:'操作',
			width:60,
			formatter:function(value,row){
				// 操作按钮
				var operationButtons = '<div class="btn-group">';
                operationButtons += '<a class="btn btn-xs btn-azure dropdown-toggle" data-toggle="dropdown" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>';
                operationButtons += '<ul class="dropdown-menu dropdown-azure">';
                operationButtons +=  '<li><a href="javascript:server.openModalBox(\'/manage/serviceManage/company/edit/' + row.id + '/1\',\'编辑\',800);"> 编辑</a></li>';
                operationButtons +=  '<li><a href="javascript:server.deleteObject(\''+row.id+'\',\'/manage/serviceManage/company/delete\',common.paginationQuery,server.currentPage);"> 删除</a></li>';
                operationButtons += '</ul>';
                operationButtons +=  '</div>';
				return operationButtons;
			}
		}]
	});
}

common.validate = function(){
	if(verify.isNull($("#companyName").val())){
		server.alert("公司名称不可为空");
		return false;
	}
	
	if(verify.isNull($("#socialCreditCode").val())){
		server.alert("统一社会信用代码不可为空");
		return false;
	}
	if(verify.isNull($("#legalPerson").val())){
		server.alert("法人不可为空 ");
		return false;
	}
	
	if(!verify.isIdentityCard($("#legalPersonIdNumber").val())){
		server.alert("请输入格式正确的身份证号");
		return false;
	}
	if(!verify.isMobileOrPhone($("#officeContactNumber").val())){
		server.alert("请输入格式正确的联系方式");
		return false;
	}
	if(verify.isNull($("#district").val())){
		server.alert("请选择区、县");
		return false;
	}
	return true;
}
